package com.neuedu.vuejsserver.controller;

import com.neuedu.entity.Dept;
import com.neuedu.entity.Menu;
import com.neuedu.vuejsserver.domain.Page;
import com.neuedu.vuejsserver.service.DeptService;
import com.neuedu.vuejsserver.service.MenuService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 项目：      jweb
 * 类名:       DeptController
 * 创建时间：  2023/11/24 14：03
 * 描述 :
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 *
 */
@WebServlet("/menu")
public class MenuController extends BaseController   {

    MenuService menuService = new MenuService();
    
    protected void deleteById(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        boolean success = menuService.deleteById(req);

        Map result  = new HashMap();
        result.put("success",success);

        super.writeJSON(resp,result);
    }

    /**
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void save(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        boolean success = menuService.save(req);

        Map result  = new HashMap();
        result.put("success",success);

        super.writeJSON(resp,result);
    }

    protected void update(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        boolean success = menuService.update(req);

        Map result  = new HashMap();
        result.put("success",success);

        super.writeJSON(resp,result);
    }
    protected void queryById(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Menu menu = menuService.queryById(req);
        //将数据响应成json字符串
        super.writeJSON(resp,menu);
    }

    protected void list(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Page page = menuService.queryList(req);
        super.writeJSON(resp,page);
    }

    //http://127.0.0.1:8080/server/menu?_type=getParent&parentId=1
    //http://127.0.0.1:8080/server/menu?_type=getParent
    protected void getParent(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       List<Menu> list = menuService.getParent(req);
        super.writeJSON(resp,list);
    }



}
